package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.LoginUser;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController//响应Json
@RequestMapping("user")
public class UserController {

    //localhost:8080/user/register?username=songge&password=niupi&age=30&gender=male
    @RequestMapping("register")
    public BaseRespVo register(String username,String password,Integer age,String gender) {
        return BaseRespVo.ok();
    }
    //localhost:8080/user/register2?username=songge&password=niupi&age=30&gender=male
    //&hobbys=sing&hobbys=dance&hobbys=rap&hobbys=basketball
    @RequestMapping("register2")
    public BaseRespVo register2(String username,String password,Integer age,String gender,String[] hobbys) {
        return BaseRespVo.ok();
    }
    //localhost:8080/user/register3?username=songge&password=niupi&age=30&gender=male
    //&hobbys=sing&hobbys=dance&hobbys=rap&hobbys=basketball
    //&birthday=2021-09-09 可以使用@DateTimeFormat
    //&birthday=2021/09/09 直接接收
    @RequestMapping("register3")
    public BaseRespVo register3(String username, String password, Integer age, String gender,
                                String[] hobbys, @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        return BaseRespVo.ok();
    }

    //localhost:8080/user/register4?username=songge&password=niupi&age=30&gender=male
    //&hobbys=sing&hobbys=dance&hobbys=rap&hobbys=basketball
    //&birthday=2021-09-09
    @RequestMapping("register4")
    public BaseRespVo register4(String username, String password, Integer age, String gender,
                                String[] hobbys, Date birthday) {
        return BaseRespVo.ok();
    }

    //请求参数名和JavaBean的成员变量名（set方法）对应
    //localhost:8080/user/register5?username=songge&password=niupi&age=30&gender=male
    //&hobbys=sing&hobbys=dance&hobbys=rap&hobbys=basketball
    //&birthday=2021-09-09
    @RequestMapping("register5")
    public BaseRespVo register5(LoginUser user) {
        return BaseRespVo.ok();
    }

    //String sort,String order
    //localhost:8080/user/list1?username=songge&password=niupi&age=30&gender=male
    //&hobbys=sing&hobbys=dance&hobbys=rap&hobbys=basketball
    //&birthday=2021-09-09&sort=username&order=asc
    @RequestMapping("list1")
    public BaseRespVo list1(LoginUser user, String sort, String order) {
        return BaseRespVo.ok();
    }

    @RequestMapping("list2")
    public BaseRespVo list2(LoginUser user, BaseParam baseParam) {
        return BaseRespVo.ok();
    }
    @RequestMapping("list3")
    public BaseRespVo list3(LoginUser user) {
        return BaseRespVo.ok();
    }
}
